home *** CD-ROM | disk | FTP | other *** search
- PROGRAM MakeKbd;
- TYPE
- { This program is an example of how to read a TEXT File and Write out a }
- {(file consisting of Pascal "Records"}
- STR9 = STRING[9]; {Define a String Type that is common to all}
- KeyRec = RECORD {Define a record of 5 integers and a 9 byte string}
- KeyCode:INTEGER;
- KLabel:STR9;
- KeyH:INTEGER;
- KeyW:INTEGER;
- KeyX:INTEGER;
- KeyY:INTEGER;
- END;
- InFileT = File OF TEXT;{Define a Text File Type}
- OutFileT = FILE OF KeyRec;{ Define a "Record File Type"}
- VAR
- {Declare are file variables}
- Infile: InfileT; OutFile:OutFileT;
- {Define a Boolean for EOF Detection}
- EOF_Flag: BOOLEAN;
- IC,OC,I: INTEGER;{IC::= Input Counter, OC::= Output Counter}
- INCode,InH,InW,InX,InY:INTEGER; {Input Integers}
- InLabel:STR9; {Input String}
- KR: KeyRec; {Output Record}
- PROCEDURE OpenFiles;
- BEGIN
- OC:=0; {Set input/output counters to 0}
- IC:=0;
- RESET(InFile,'A:\Keyboard.TXT'); {Open the Text file for input}
- REWRITE(OutFile,'A:\Keyboard.REC');{open the output "record file"}
- {note: the above 2 files n file for input}
- REWRITE(OutFile,'A:\Keyboard.REC');{open the output "record file"}
- {note: the above 2 files names are hard coded they don't have to be}
- END;
- PROCEDURE DoFiles;
- BEGIN
- READ(InFile,InCode); {Read first integer off a line of Text}
- READ(InFile,InH); {Read 2nd integer off a line of text}
- READ(InFile,INW); {Read 3rd integer off the text line}
- READ(InFile,InX); {Read 4th integer off the text line}
- READ(InFile,InY); {Read 5th Integer off the text line}
- READLN(InFile,InLabel); {Read the String and position at the}
- {Start of the next line}
- {note: numeric variables are delimited}
- {by a Space}
- IC:=IC+1; {Add 1 to in record count}
- Eof_flag := EOF(INFile); {Test for End of File}
- {Even if we got an EOF write the last record}
- {because the eof was caused by a lack of a}
- {next text line while doing the READLN}
- KR.KeyCode:=InCode; {move input variable contents to output}
- KR.KLabel:= InLabel; {record}
- KR.KeyW:=InW;
- KR.KeyH:=InH;
- KR.KeyX:=InX;
- KR.KeyY:=Iny;
- OutFile^ := KR; {Store the output record in file buffer}
- Put(OutFile); {Write the record}
- OC:=OC + 1; {increment output record count}
- IF EOF_Flag THEN {at end of file write summary}
- {note this appears on the top of screen when this }
- {program runs under Gem}
- BEGIN
- Writeln(IC:4, ' Records read ',OC:4,' Records written');
- Close(InFile); {you have to close or tos will run out of}
- Close(OutFile); {file handles}
- END;
- END;
- BEGIN {Main} {look ma know Gem}
- Openfiles;
- WHILE (EOF_Flag = False) DO DoFiles;
- END.
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;